home *** CD-ROM | disk | FTP | other *** search
- /* some functions to respond to various user inputs...
- * 870806-13-... ^z
- */
-
- #include <stdio.h> /* for FILE, printf(), etc. */
- #include <strings.h> /* for strcpy(), etc. */
- #include <unix.h> /* for exit(), etc. */
- #include <proto.h> /* for function prototypes */
- #include "brwsr.h" /* for various definitions */
- #include "brwsr.proto.h" /* for my function prototypes */
-
-
- /* function to interpret a command to move around in the current level
- * of the browser display ... handles "+", "-", and "<return>" ... calls
- * routine make_move() to do the real work....
- */
-
- void do_move (cmd)
- char cmd[];
- {
- long move;
- extern FILE *doc_file;
-
- if (doc_file == NULL)
- {
- beep ();
- printf ("No file open!\n");
- return;
- }
-
- if (cmd[1] == '\0')
- strcat (cmd, "1");
- move = atol (cmd);
- make_move (move);
- show_current_item ();
- }
-
-
- /* function to do the actual moving around in the INDEX or CONTEXT or
- * TEXT displays .... Safety features prevent user from going
- * off the end of the file in either direction....
- * make_move() returns FALSE if it fails to completely execute the move
- * (i.e., if the move would have run off either end of the file) and
- * beeps at the user ... it returns TRUE if the move succeeds....
- */
-
- int make_move (n)
- long n;
- {
- int r;
- PTR_REC get_ptr_rec ();
- extern long current_item[], min_item[], max_item[];
- extern int level;
- extern char *subset;
-
- r = TRUE;
- switch (level)
- {
- case INDEX:
- current_item[INDEX] += n;
- if (current_item[INDEX] < min_item[INDEX])
- {
- current_item[INDEX] = min_item[INDEX];
- r = FALSE;
- }
- if (current_item[INDEX] > max_item[INDEX])
- {
- current_item[INDEX] = max_item[INDEX];
- r = FALSE;
- }
- break;
-
- case CONTEXT:
- if (subset == NULL)
- {
- current_item[CONTEXT] += n;
- if (current_item[CONTEXT] < min_item[CONTEXT])
- {
- current_item[CONTEXT] = min_item[CONTEXT];
- r = FALSE;
- }
- if (current_item[CONTEXT] > max_item[CONTEXT])
- {
- current_item[CONTEXT] = max_item[CONTEXT];
- r = FALSE;
- }
- }
- else
- r = make_subindex_move (n);
-
- current_item[TEXT] = get_ptr_rec (current_item[CONTEXT]);
- break;
-
- case TEXT:
- r = move_in_text (n);
- break;
- }
-
- if (r == FALSE)
- beep ();
- return (r);
- }
-
-
- /* move up or down the chosen number of lines of text, and put the result
- * into current_item[TEXT] ... return FALSE if attempted move would have
- * run off the end of the file, non-zero if the move was completed without
- * error....
- */
-
- int move_in_text (move)
- register long move;
- {
- int result;
- register long loc;
- extern long current_item[];
-
- result = TRUE;
- loc = current_item[TEXT];
-
- if (move < 0)
- for ( ; move < 0; ++move)
- {
- if (loc <= 0)
- {
- result = FALSE;
- break;
- }
- loc = start_of_line (loc - 1);
- }
-
- else if (move > 0)
- for ( ; move > 0; --move)
- {
- loc = next_line (loc);
- if (loc >= max_item[TEXT])
- {
- result = FALSE;
- loc = start_of_line (max_item[TEXT]);
- break;
- }
- }
-
- current_item[TEXT] = loc;
- return (result);
- }
-
-
- /* make a move in the working subindex ... must just step along in
- * whichever direction is desired until either hitting the end (in
- * which case the last valid item found in the subindex should be
- * returned as the current one) or finishing the requested move.
- * Return FALSE if hit a wall, TRUE otherwise....
- *
- * This routine is only called when level == CONTEXT ... since
- * in TEXT level we are just moving around in the full text of
- * the document file, and in the INDEX level we count and display
- * even items with zero occurrences in the subindex...
- *
- * This routine is only called when subset != NULL, since if there
- * is no working subset the move becomes trivial arithmetic.
- *
- * This routine is only called when either current_item[CONTEXT]
- * is a good item in the subset already, or when there is a certainty
- * that a good item will be found in the subsequent scan (specifically,
- * when scanning down to find the first good item when called from
- * do_descend () ....).
- */
-
- int make_subindex_move (move)
- long move;
- {
- register long i, last_good_item;
- int result;
- PTR_REC get_ptr_rec ();
- extern long current_item[], min_item[], max_item[];
- extern char *subset;
-
- result = TRUE;
- last_good_item = current_item[CONTEXT];
-
- if (move >= 0)
- {
- for (i = 0; i < move; ++i)
- {
- while (++current_item[CONTEXT] <= max_item[CONTEXT] &&
- ! get_subset_bit ((long)
- get_ptr_rec (current_item[CONTEXT])));
- if (current_item[CONTEXT] > max_item[CONTEXT])
- break;
- last_good_item = current_item[CONTEXT];
- }
- if (current_item[CONTEXT] > max_item[CONTEXT])
- {
- result = FALSE;
- current_item[CONTEXT] = last_good_item;
- }
- }
- else
- {
- for (i = 0; i > move; --i)
- {
- while (--current_item[CONTEXT] >= min_item[CONTEXT] &&
- ! get_subset_bit ((long)
- get_ptr_rec (current_item[CONTEXT])));
- if (current_item[CONTEXT] < min_item[CONTEXT])
- break;
- last_good_item = current_item[CONTEXT];
- }
- if (current_item[CONTEXT] < min_item[CONTEXT])
- {
- result = FALSE;
- current_item[CONTEXT] = last_good_item;
- }
- }
- return (result);
- }
-
-